
/*
 * This is the extension predicate for an activity associated
 * with service '{http://www.pi4soa.org/AuctionHouseBuyer}AuctionHouse'
 * and behavior 'main_AuctionHouse'. The name of the
 * activity is 'MaxBidNotReached'.
 */
package org.pi4soa.auctionhousebuyer.auctionhouse.main_auctionhouse;

import org.pi4soa.service.extensions.DefaultActivityExtension;
import org.pi4soa.service.extensions.PredicateExtension;
import org.pi4soa.service.extensions.ExtensionContext;
import org.pi4soa.service.ServiceEvent;
import org.pi4soa.service.UnresolvedConstraintException;
import org.pi4soa.service.ServiceException;
import org.pi4soa.service.DeferProcessingException;

import dk.itu.amds.auctionhouse.domain.AuctionItem;

/**
 * This class has been autogenerated to implement the custom
 * predicate within a service endpoint description.
 */
public class MaxBidNotReachedPredicate extends DefaultActivityExtension
					implements PredicateExtension {

	/**
	 * The constructor for the predicate extension.
	 */
	public MaxBidNotReachedPredicate() {
	}
	
	/**
	 * This method determines whether the predicate extension
	 * is satisfied.
	 * 
	 * @param context The context
	 * @param event The current event being processed
	 * @return Whether the extension predicate is satisfied
	 * @exception UnresolvedConstraintException The predicate cannot
	 * 				be resolved due to lack of information
	 * @exception DeferProcessingException Suspend processing
	 * @exception ServiceException Failed to evaluate predicate
	 */
	public boolean isSatisfied(ExtensionContext context,
					ServiceEvent event)
			throws UnresolvedConstraintException,
					DeferProcessingException, ServiceException {
		boolean ret=false;

		float currentBid = Float.parseFloat(context.getVariable("currentBid").toString());
		
		AuctionItem auctionItem = (AuctionItem) context.getVariable("auctionItem");
		
		float highestBid = auctionItem.getHighestBid();
		float maxPrice = auctionItem.getMaxPrice();
		
		ret = currentBid < maxPrice && currentBid > highestBid && !auctionItem.isAuctionDone();
		
		return(ret);
	}
}	